<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="reinforcement-learning," />





  <link rel="alternate" href="/atom.xml" title="Kintoki's Blog" type="application/atom+xml" />






<meta name="description" content="接下来我们回顾一下动态规划算法(DP)和蒙特卡罗方法(MC)的特点，对于动态规划算法有如下特性：  需要环境模型，即状态转移概率$P_{sa}$ 状态值函数的估计是自举的(bootstrapping)，即当前状态值函数的更新依赖于已知的其他状态值函数。  相对的，蒙特卡罗方法的特点则有：  可以从经验中学习不需要环境模型 状态值函数的估计是相互独立的 只能用于episode tasks  而我们希">
<meta name="keywords" content="reinforcement-learning">
<meta property="og:type" content="article">
<meta property="og:title" content="强化学习（五）时间差分学习">
<meta property="og:url" content="http://yoursite.com/2019/11/24/RL5-TD-learning/index.html">
<meta property="og:site_name" content="Kintoki&#39;s Blog">
<meta property="og:description" content="接下来我们回顾一下动态规划算法(DP)和蒙特卡罗方法(MC)的特点，对于动态规划算法有如下特性：  需要环境模型，即状态转移概率$P_{sa}$ 状态值函数的估计是自举的(bootstrapping)，即当前状态值函数的更新依赖于已知的其他状态值函数。  相对的，蒙特卡罗方法的特点则有：  可以从经验中学习不需要环境模型 状态值函数的估计是相互独立的 只能用于episode tasks  而我们希">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://static.zybuluo.com/Kintoki/jr1dxnxa6qmbhszm76ds3c0b/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-05%20%E4%B8%8B%E5%8D%889.48.30.png">
<meta property="og:image" content="http://static.zybuluo.com/Kintoki/h6korj3ipv13w7slzbw29pku/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-06%20%E4%B8%8B%E5%8D%889.28.07.png">
<meta property="og:image" content="http://static.zybuluo.com/Kintoki/yt605ny9pl3vq47wu4nbkjds/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-06%20%E4%B8%8B%E5%8D%889.52.57.png">
<meta property="og:image" content="http://static.zybuluo.com/Kintoki/jovo7i3whlczd1sqcb6v05h4/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-09%20%E4%B8%8A%E5%8D%8812.35.01.png">
<meta property="og:updated_time" content="2019-11-24T11:45:51.547Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="强化学习（五）时间差分学习">
<meta name="twitter:description" content="接下来我们回顾一下动态规划算法(DP)和蒙特卡罗方法(MC)的特点，对于动态规划算法有如下特性：  需要环境模型，即状态转移概率$P_{sa}$ 状态值函数的估计是自举的(bootstrapping)，即当前状态值函数的更新依赖于已知的其他状态值函数。  相对的，蒙特卡罗方法的特点则有：  可以从经验中学习不需要环境模型 状态值函数的估计是相互独立的 只能用于episode tasks  而我们希">
<meta name="twitter:image" content="http://static.zybuluo.com/Kintoki/jr1dxnxa6qmbhszm76ds3c0b/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-05%20%E4%B8%8B%E5%8D%889.48.30.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/11/24/RL5-TD-learning/"/>





  <title>强化学习（五）时间差分学习 | Kintoki's Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Kintoki's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我们所度过的每个平凡的日常，也许就是连续发生的奇迹</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-留言">
          <a href="/board/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heart"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/24/RL5-TD-learning/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Kintoki">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Kintoki's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">强化学习（五）时间差分学习</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-24T19:45:51+08:00">
                2019-11-24
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2019/11/24/RL5-TD-learning/" class="leancloud_visitors" data-flag-title="强化学习（五）时间差分学习">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">Visitors&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  1,887
                </span>
              

              

              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>接下来我们回顾一下动态规划算法(DP)和蒙特卡罗方法(MC)的特点，对于动态规划算法有如下特性：</p>
<ul>
<li>需要环境模型，即状态转移概率$P_{sa}$</li>
<li>状态值函数的估计是自举的(<em>bootstrapping</em>)，即当前状态值函数的更新依赖于已知的其他状态值函数。</li>
</ul>
<p>相对的，蒙特卡罗方法的特点则有：</p>
<ul>
<li>可以从经验中学习不需要环境模型</li>
<li>状态值函数的估计是相互独立的</li>
<li>只能用于episode tasks</li>
</ul>
<p>而我们希望的算法是这样的：</p>
<ul>
<li>不需要环境模型</li>
<li>它不局限于episode task，可以用于连续的任务</li>
</ul>
<p>本文介绍的<strong>时间差分学习</strong>(Temporal-Difference learning, TD learning)正是具备了上述特性的算法，它结合了DP和MC，并兼具两种算法的优点。</p>
<a id="more"></a>
<h2 id="TD-Learing思想"><a href="#TD-Learing思想" class="headerlink" title="TD Learing思想"></a>TD Learing思想</h2><p>在介绍TD learning之前，我们先引入如下简单的蒙特卡罗算法，我们称为<strong>constant-$\alpha$ MC</strong>，它的状态值函数更新公式如下：<br>$$ V(s_t) \leftarrow V(s_t) + \alpha[R_t - V(s_t)] \tag {1}$$<br>其中$R_t$是每个episode结束后获得的实际累积回报，$\alpha$是学习率，这个式子的直观的理解就是<strong>用实际累积回报$R_t$作为状态值函数$V(s_t)$的估计值</strong>。具体做法是对每个episode，考察实验中$s_t$的实际累积回报$R_t$和当前估计$V(s_t)$的偏差值，并用该偏差值乘以学习率来更新得到$V(S_t)$的新估值。</p>
<p>现在我们将公式修改如下，把$R_t$换成$r_{t+1} + \gamma V(s_{t+1})$，就得到了TD(0)的状态值函数更新公式：<br>$$V(s_t) \leftarrow V(s_t) + \alpha[r_{t+1} + \gamma V(s_{t+1}) - V(s_t)] \tag {2}$$</p>
<p>为什么修改成这种形式呢，我们回忆一下状态值函数的定义：<br>$$V^{\pi}(s)=E_{\pi}[r(s’|s,a)+\gamma V^{\pi}(s’)] \tag {3}$$<br>容易发现这其实是根据(3)的形式，利用真实的立即回报$r_{t+1}$和下个状态的值函数$V(s_{t+1})$来更新$V(s_t)$，这种就方式就称为时间差分(temporal difference)。由于我们没有状态转移概率，所以要利用多次实验来得到期望状态值函数估值。类似MC方法，在足够多的实验后，状态值函数的估计是能够收敛于真实值的。</p>
<p>那么MC和TD(0)的更新公式的有何不同呢？我们举个例子，假设有以下8个episode, 其中A-0表示经过状态A后获得了回报0:</p>
<table>
<thead>
<tr>
<th style="text-align:center">index</th>
<th style="text-align:center">samples</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">episode 1</td>
<td style="text-align:center">A-0, B-0</td>
</tr>
<tr>
<td style="text-align:center">episode 2</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 3</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 4</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 5</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 6</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 7</td>
<td style="text-align:center">B-1</td>
</tr>
<tr>
<td style="text-align:center">episode 8</td>
<td style="text-align:center">B-0</td>
</tr>
</tbody>
</table>
<p>首先我们使用constant-$\alpha$ MC方法估计状态A的值函数，其结果是$V(A)=0$，这是因为状态A只在episode 1出现了一次，且其累计回报为0。</p>
<p>现在我们使用TD(0)的更新公式，简单起见取$\lambda=1$，我们可以得到$V(A)=0.75$。这个结果是如何计算的呢？ 首先，状态B的值函数是容易求得的，B作为终止状态，获得回报1的概率是75%，因此$V(B)=0.75$。接着从数据中我们可以得到状态A转移到状态B的概率是100%并且获得的回报为0。根据公式(2)可以得到$V(A) \leftarrow V(A) + \alpha[0 + \lambda V(B) - V(A)]$，可见在只有$V(A)=\lambda V(B)=0.75$的时候，式(2)收敛。对这个例子，可以作图表示：<br><img src="http://static.zybuluo.com/Kintoki/jr1dxnxa6qmbhszm76ds3c0b/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-05%20%E4%B8%8B%E5%8D%889.48.30.png" alt="屏幕快照 2016-01-05 下午9.48.30.png-24.1kB"><br>可见式(2)由于能够利用其它状态的估计值，其得到的结果更加合理，并且由于不需要等到任务结束就能更新估值，也就不再局限于episode task了。此外，实验表明TD(0)从收敛速度上也显著优于MC方法。</p>
<p>将式(2)作为状态值函数的估计公式后，前面文章中介绍的<strong>策略估计</strong>算法就变成了如下形式，这个算法称为TD prediction:</p>
<p><em>输入：待估计的策略$\pi$<br>任意初始化所有$V(s)$，($e.g.,V(s)=0,\forall s\in s^{+}$)<br>Repeat(对所有episode):<br>　　初始化状态 $s$<br>　　Repeat(对每步状态转移):<br>　　　　$a\leftarrow$策略$\pi$下状态$s$采取的动作<br>　　　　采取动作$a$，观察回报$r$，和下一个状态$s’$<br>　　　　$V(s) \leftarrow V(s) + \alpha[r + \lambda V(s’) - V(s)]$<br>　　　　$s\leftarrow s’$<br>　　Until $s_t$ is terminal<br>　Until 所有$V(s)$收敛<br>输出$V^{\pi}(s)$</em></p>
<h2 id="Sarsa算法"><a href="#Sarsa算法" class="headerlink" title="Sarsa算法"></a>Sarsa算法</h2><p>现在我们利用TD prediction组成新的强化学习算法，用到决策/控制问题中。在这里，强化学习算法可以分为<strong>在策略(on-policy)</strong>和<strong>离策略(off-policy)</strong>两类。首先要介绍的sarsa算法属于on-policy算法。<br>与前面DP方法稍微有些区别的是，sarsa算法估计的是<strong>动作值函数(Q函数)</strong>而非状态值函数。也就是说，我们估计的是策略$\pi$下，任意状态$s$上所有可执行的动作a的动作值函数$Q^{\pi}(s,a)$，Q函数同样可以利用TD Prediction算法估计。如下就是一个状态-动作对序列的片段及相应的回报值。<br><img src="http://static.zybuluo.com/Kintoki/h6korj3ipv13w7slzbw29pku/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-06%20%E4%B8%8B%E5%8D%889.28.07.png" alt="屏幕快照 2016-01-06 下午9.28.07.png-17.3kB"><br>给出sarsa的动作值函数更新公式如下：<br>$$Q(s_t,a_t) \leftarrow Q(s_t,a_t) + \alpha[r_{t+1} + \lambda Q(s_{t+1}, a_{t+1}) - Q(s_t,a_t)] \tag {4}$$</p>
<p>可见式(4)与式(2)的形式基本一致。需要注意的是，对于每个非终止的状态$s_t$，在到达下个状态$s_{t+1}$后，都可以利用上述公式更新$Q(s_t,A_t)$，而如果$s_t$是终止状态，则要令$Q(s_{t+1}=0,a_{t+1})$。由于动作值函数的每次更新都与$(s_t, a_t,r_{t+1},s_{t+1},a_{t+1})$相关，因此算法被命名为sarsa算法。sarsa算法的完整流程图如下：<br><img src="http://static.zybuluo.com/Kintoki/yt605ny9pl3vq47wu4nbkjds/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-06%20%E4%B8%8B%E5%8D%889.52.57.png" alt="屏幕快照 2016-01-06 下午9.52.57.png-61kB"><br>算法最终得到所有状态-动作对的Q函数，并根据Q函数输出最优策略$\pi$</p>
<h2 id="Q-learning"><a href="#Q-learning" class="headerlink" title="Q-learning"></a>Q-learning</h2><p>在sarsa算法中，<strong>选择动作时遵循的策略</strong>和<strong>更新动作值函数时遵循的策略</strong>是相同的，即$\epsilon-greedy​$的策略，而在接下来介绍的Q-learning中，动作值函数更新则<strong>不同于选取动作时遵循的策略</strong>，这种方式称为<strong>离策略(Off-Policy)</strong>。Q-learning的动作值函数更新公式如下：<br>$$Q(s_t,a_t) \leftarrow Q(s_t,a_t) + \alpha[r_{t+1} + \lambda \max_{a} Q(s_{t+1}, a) - Q(s_t,a_t)] \tag {5}$$<br>可以看到，Q-learning与sarsa算法最大的不同在于<strong>更新Q值的时候，直接使用了最大的$Q(s_{t+1},a)$值——相当于采用了$Q(s_{t+1},a)$值最大的动作，并且与当前执行的策略，即选取动作$a_t$时采用的策略无关。</strong> Off-Policy方式简化了证明算法分析和收敛性证明的难度，使得它的收敛性很早就得到了证明。Q-learning的完整流程图如下：<br><img src="http://static.zybuluo.com/Kintoki/jovo7i3whlczd1sqcb6v05h4/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202016-01-09%20%E4%B8%8A%E5%8D%8812.35.01.png" alt="屏幕快照 2016-01-09 上午12.35.01.png-140.7kB"></p>
<h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>本篇介绍了TD方法思想和TD(0),Q(0),Sarsa(0)算法。TD方法结合了蒙特卡罗方法和动态规划的优点，能够应用于无模型、持续进行的任务，并拥有优秀的性能，因而得到了很好的发展，其中Q-learning更是成为了强化学习中应用最广泛的方法。在下一篇中，我们将引入<strong>资格迹(Eligibility Traces)</strong>提高算法性能，结合Eligibility Traces后，我们可以得到$Q(\lambda),Sarsa(\lambda)$等算法</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p>[1] R.Sutton et al. Reinforcement learning: An introduction, 1998</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/reinforcement-learning/" rel="tag"><i class="fa fa-tag"></i>reinforcement-learning</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/06/tensorflow-dkt/" rel="next" title="Deep knowledge tracing with Tensorflow">
                <i class="fa fa-chevron-left"></i> Deep knowledge tracing with Tensorflow
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/24/dynamic-programming/" rel="prev" title="">
                 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="Kintoki" />
            
              <p class="site-author-name" itemprop="name">Kintoki</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/jinxulin" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:jinxulin@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/jinxulin/home" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-twitter"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.cnblogs.com/jinxulin" target="_blank" title="博客园">
                      
                        <i class="fa fa-fw fa-github"></i>博客园</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#TD-Learing思想"><span class="nav-number">1.</span> <span class="nav-text">TD Learing思想</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Sarsa算法"><span class="nav-number">2.</span> <span class="nav-text">Sarsa算法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Q-learning"><span class="nav-number">3.</span> <span class="nav-text">Q-learning</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#小结"><span class="nav-number">4.</span> <span class="nav-text">小结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考资料"><span class="nav-number">5.</span> <span class="nav-text">参考资料</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kintoki</span>

  
</div>


  <div class="powered-by">  Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>


<div class="theme-info">
  Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a>
</div>
        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>  
    <span class="site-pv">
      <i class="fa fa-user"></i> 访问人数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
    <span class="site-pv">
      <i class="fa fa-eye"></i> 总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("WEB822paP0cwBpoIerKOWcF4-gzGzoHsz", "mxnf4Poo55CyjlisDHiMELxR");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
